<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ include file="/website/layout/tag.jsp"%>
<script type="text/javascript">
	$(document).ready(
		function() {
			//事件注册.
			$("#addBtn").click(addBook);
			$("#searchBtn").click(searchBook);
			$("#modifyBtn").click(modifyBook);
			$("#deployBtn").click(
				function() {
					changeBookSta("1");
				}
			);
			$("#cancelBtn").click(
				function() {
					changeBookSta("0");
				}
			);
			
			//$("#categoryId1").change(showSubCtg);
			
			//checkbox控件事件注册.
			$("[name='chkAll']").each(
				function() {
					$(this).click(function() {
						checkAll("chkAll", "chkEach");
					});
				}
			);
			$("[name='chkEach']").each(
				function() {
					$(this).click(function() {
						checkEach("chkAll", "chkEach");
					});
				}
			);
			
			//设置左菜单对应菜单CSS为选中状态.
			changeToActiveCss("menu_2010");
			
			//消息显示.
			//var msg = '<c:out value="${msg}"/>';
		//	if (msg != "") {
		//		alert(msg);
		//	}
		}
	);
	
	function searchBook() {
		$("#searchForm").submit();
	}
	
	function addBook() {
		window.location.href='${pageContext.request.contextPath}/main/enterBookModify.do?oper=new';
	}
	
	function modifyBook() {
		var checkObjs = $(":checkbox[name='chkEach']:checked");
		var len = checkObjs.length;
		if (len == 0) {
			alert("请选择要编辑的图书.");
			return false;
		}
		
		if (len > 1) {
			alert("请只选择一条图书数据.");
			return false;
		}
		
		window.location.href='${pageContext.request.contextPath}/main/enterBookModify.do?oper=modify&sysId=' + checkObjs[0].value;
	}
	
	function changeBookSta(newStatus) {
		var checkObjs = $(":checkbox[name='chkEach']:checked");
		var len = checkObjs.length;
		if (len == 0) {
			alert("请选择要修改的订单.");
			return false;
		}
		
		var bookIds = "";
		checkObjs.each(
			function() {
				bookIds += $(this).val() + ",";
			}
		);
		
		if(confirm("确定要修改图书的发布状态吗?")) {
			var action = "${pageContext.request.contextPath}/main/changeBookSta.do";
			action += "?bookIds=" + bookIds + "&newStatus=" + newStatus;
			$("#searchForm").attr("action", action);
			$("#searchForm").submit();
		}
	}
	
	function showSubCtg() {
		var sysId = $(this).val();
		if (sysId != undefined && $.trim(sysId) != "") {
			$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/pub/findSubCtg.do",
				context:this,
				dataType:"json",
				data:"parentId=" + sysId,
				success:showSubCtgCallback,
				error:function(){alert("发生了错误.");},
			});
		} else {
			$("#categoryId2").empty();
		}
	}
	
	function showSubCtgCallback(result) {
		if (result.status == "OK") {
			$("#categoryId2").empty();
			
			$("#categoryId2").append("<option value=''></option>" );
			var list = result.data;
			for (var i=0; i<list.length; i++) {
				var ctg = list[i];
				$("#categoryId2").append("<option value='" + ctg.sysId + "'> " + ctg.name + "</option>" );
			}
		} else {
			alert(result.msg);
		}
	}
	
</script>
<div id="content_right">
	<div style="width:100%;height:35px;line-height:35px;text-align:left;background-color:#F5FAFA;font-weight:bold; ">图书 > 图书管理 > 图书列表</div>
	<div id="searchArea">
	
		<table width="100%" cellspacing="0">
			<tr>
				<td width="60px" align="right">图书名:</td>
				<td width="80px" align="left"></td>
				<td width="60px" align="right">ISBN:</td>
				<td width="120px" align="left"></td>
				<td width="60px" align="right">出版社:</td>
				<td width="80px" align="left"></td>
				<td width="60px" align="right">在库册数:</td>
				<td width="80px" align="left"></td>
				<td width="60px" align="right">货架号:</td>
				<td width="80px" align="left"></td>
				<td></td>
			</tr>
			<tr>
				<td align="right">图书分类:</td>
				<td align="left" colspan="3">
			
				</td>
				<td align="right">内部编号:</td>
				<td align="left">
				
				</td>
				<td align="right">价格:</td>
				<td align="left">
					<select style="width:100px ">
						<option value="1">0~10</option>
						<option value="1">11~20</option>
						<option value="1">21~30</option>
						<option value="1">31~40元</option>
						<option value="1">51元以上</option>
					</select>
				</td>
				<td align="right">是否发布:</td>
				<td align="left">
				
				</td>
				<td>
				</td>
			</tr>
			<tr>
				<td colspan="11">
					<div class="buttons" style="float:right; margin-right:40px;">
						<a id="searchBtn" href="#">
							<img src="../images/btn_search.gif" alt=""/> 
							检索
						</a>
					</div>
				</td>
			</tr>
		</table>
		
	</div>
	<div id="btnArea">
		<div class="buttons">
			<a id="addBtn" href="#">
				<img src="../images/btn_apply.png" alt=""/> 
				添加
			</a>
			<a id="modifyBtn" href="#">
				<img src="../images/btn_textfield_key.png" alt=""/> 
				修改
			</a>
			<a id="deployBtn" href="#">
				<img src="../images/btn_cross.png" alt=""/> 
				发布图书
			</a>
			<a id="cancelBtn" href="#">
				<img src="../images/btn_cross.png" alt=""/> 
				下架图书
			</a>
		</div>
	</div>
	<div style="clear:both; "></div>
	<div id="resultArea" style="height:400px; ">
		<table class="dataTable" cellspacing="0"> 
			<tr> 
			<th scope="col" width="26px;"><input type="checkbox" name="chkAll"/></th> 
			<th scope="col" width="135px">图书名</th> 
			<th scope="col" width="90px">ISBN</th> 
			<th scope="col" width="50px">内部</br>编号</th> 
			<th scope="col" width="50px">是否</br>发布</th> 
			<th scope="col" width="105px">出版社</th> 
			<th scope="col" width="30px">在库</th> 
			<th scope="col" width="50px">货架号</th> 
			<th scope="col" width="75px">分类1</th> 
			<th scope="col" width="75px">分类2</th> 
			<th scope="col" width="100px">作者</th> 
			<th scope="col" width="55px">价格</th> 
			<th scope="col" width="45px">购买</br>价格</th> 
			<th scope="col" width="55px">适宜</br>年龄</th>
			<th scope="col">国家</th>
			</tr> 
		<!--  	<c:forEach var="item" items="${goodsList}" varStatus="status">-->
			<tr> 
			<td class="row"> <input type="checkbox" name="chkEach" value="#"/></td>
			<td class="row">#</td> 
			<td class="row">#</td> 
			<td class="row">#</td> 
			<td class="row">#</td> 
			<td class="row">#</td> 
			<td class="row">#</td> 
			<td class="row">#</td> 
			<td class="row">少儿图书</td>
			<td class="row">少儿绘本</td> 
			<td class="row">#</td>
			<td class="row">#</td>
			<td class="row">#</td>
			<td class="row">3~6岁</td>
			<td class="row">#</td>
			</tr> 
		<!-- 	</c:forEach>  -->
		</table> 
	</div>
</div>